/*
 * FileHandlerFactory.cs - Wordtrainer
 * 
 * Copyright (C) 1998-2008 Markus Kilås
 *               
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 *
 * Authors:
 *   Markus Kilås <markus@markuspage.com>
 */

using System;
using System.Collections;
using Gtk;

namespace WtSharp
{
	
	
	public class FileHandlerFactory
	{
		private Hashtable m_FileHandlers = new Hashtable();
		
		public FileHandlerFactory()
		{
			Wt12FileHandler wt12Handler = new Wt12FileHandler();
			foreach(FileFilter filter in wt12Handler.FileFilters)
			{
				m_FileHandlers.Add(filter, wt12Handler);
			}
			//TODO add more handlers
		}
		
		private static FileHandlerFactory instance;
		
		public static FileHandlerFactory Instance {
			get
			{
				if(instance == null)
				{
					instance = new FileHandlerFactory();
				}
				return instance;
			}
		}
		
		public IFileHandler GetFileHandler(string fileName, FileFilter filter)
		{
			if(filter == null) 
			{
				// TODO: Look at file extension
				
				return new Wt12FileHandler();
			}
			return (IFileHandler) m_FileHandlers[filter];
		}
		
		public ICollection FileFilters
		{
			get
			{
				return m_FileHandlers.Keys;
			}
		}
	}
}
